﻿//------------------------------------------------------------------------------
// The contents of this file are subject to the Microsoft Public License (Ms-PL)
// You may obtain a copy of the License at http://psadmin.codeplex.com/license. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, 
// WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations 
// under the License.
// 
// The initial developer is Ben Foster (ben.foster@retroviz.com)
// Copyright (c) Retroviz Limited (http://www.retroviz.com).
// All Rights Reserved.
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using PSAdmin.Core.Security;

namespace PSAdmin.Core.Domain
{
    public class PSScript : Entity<PSScript, int>
    {
        public override int Id { get; set; }
        [Required]
        public virtual string Name { get; set; }
        public virtual string Description { get; set; }
        [Required]
        public virtual string CommandText { get; set; }

        public virtual bool Impersonate { get;set; }
        public virtual string Username { get; set; }            
        public virtual string Password { get; set; }       
        public virtual string Domain { get; set; }

        public virtual ICollection<UserRole> Roles { get; set; }

        public virtual ICollection<PSScriptVariable> Variables { get; private set; }

        public PSScript() {
            Variables = new HashSet<PSScriptVariable>();
            Roles = new HashSet<UserRole>();
        }

        public virtual void AddScriptVariable(PSScriptVariable variable) {
            variable.Script = this;
            this.Variables.Add(variable);
        }

        public virtual bool HasVariables
        {
            get { return Variables.Count > 0; }
        }

        public virtual void ClearCredentials() {
            this.Username = string.Empty;
            this.Password = string.Empty;
            this.Domain = string.Empty;
        }
    }
}
